package com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjda;

import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjda.vo.DataQueryQjdaPageReqVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjda.vo.DataQueryQjdaRespVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjda.vo.DataQueryQjdaSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.queryinfo.framework.common.pojo.PageParam;
import com.sugar.queryinfo.framework.common.pojo.PageResult;
import com.sugar.queryinfo.framework.common.pojo.CommonResult;
import com.sugar.queryinfo.framework.common.util.object.BeanUtils;
import static com.sugar.queryinfo.framework.common.pojo.CommonResult.success;

import com.sugar.queryinfo.framework.excel.core.util.ExcelUtils;

import com.sugar.queryinfo.module.business.dal.dataobject.dataqueryqjda.DataQueryQjdaDO;
import com.sugar.queryinfo.module.business.service.dataqueryqjda.DataQueryQjdaService;

@Tag(name = "管理后台 - 数据查询-全景档案")
@RestController
@RequestMapping("/business/data-query-qjda")
@Validated
public class DataQueryQjdaController {

    @Resource
    private DataQueryQjdaService dataQueryQjdaService;

    @PostMapping("/create")
    @Operation(summary = "创建数据查询-全景档案")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjda:create')")
    public CommonResult<Long> createDataQueryQjda(@Valid @RequestBody DataQueryQjdaSaveReqVO createReqVO) {
        return success(dataQueryQjdaService.createDataQueryQjda(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新数据查询-全景档案")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjda:update')")
    public CommonResult<Boolean> updateDataQueryQjda(@Valid @RequestBody DataQueryQjdaSaveReqVO updateReqVO) {
        dataQueryQjdaService.updateDataQueryQjda(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除数据查询-全景档案")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjda:delete')")
    public CommonResult<Boolean> deleteDataQueryQjda(@RequestParam("id") Long id) {
        dataQueryQjdaService.deleteDataQueryQjda(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除数据查询-全景档案")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjda:delete')")
    public CommonResult<Boolean> deleteDataQueryQjdaList(@RequestParam("ids") List<Long> ids) {
        dataQueryQjdaService.deleteDataQueryQjdaListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据查询-全景档案")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjda:query')")
    public CommonResult<DataQueryQjdaRespVO> getDataQueryQjda(@RequestParam("id") Long id) {
        DataQueryQjdaDO dataQueryQjda = dataQueryQjdaService.getDataQueryQjda(id);
        return success(BeanUtils.toBean(dataQueryQjda, DataQueryQjdaRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得数据查询-全景档案分页")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjda:query')")
    public CommonResult<PageResult<DataQueryQjdaRespVO>> getDataQueryQjdaPage(@Valid DataQueryQjdaPageReqVO pageReqVO) {
        PageResult<DataQueryQjdaDO> pageResult = dataQueryQjdaService.getDataQueryQjdaPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DataQueryQjdaRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出数据查询-全景档案 Excel")
    @PreAuthorize("@ss.hasPermission('business:data-query-qjda:export')")
    //@ApiAccessLog(operateType = EXPORT)
    public void exportDataQueryQjdaExcel(@Valid DataQueryQjdaPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DataQueryQjdaDO> list = dataQueryQjdaService.getDataQueryQjdaPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "数据查询-全景档案.xls", "数据", DataQueryQjdaRespVO.class,
                        BeanUtils.toBean(list, DataQueryQjdaRespVO.class));
    }

}